/**
 * 
 * @project
 * @author yanwl
 * @version 1.0
 * @data 2014-08-21
 */
package com.chnbst.bstyun.core.common;

import java.text.ParseException;

public class PriceUtil {
	/**
	 * 产品价格计算
	 * @param basePrice 产品报价
	 * @param baseUserLife 产品基础年限
	 * @param baseUserNum 产品基础用户数
	 * @param userLife 产品实际选择年限
	 * @param userNum 产品实际选择用户数
	 * @return double 产品价格
	 */
	public static double getPrice(double basePrice,int baseUserLife,int baseUserNum,int userLife,int userNum){
		Double price = (basePrice / baseUserLife / baseUserNum / 12)*userLife*userNum;
		return price;
	}
	
	/**
	 * 产品价格计算
	 * @param goodsPrice 商品报价
	 * @param feeFormula 商品计费模式
	 * @param feeBasenum 商品基数
	 * @param userYear 产品实际选择年限
	 * @param userNum 产品实际选择用户数
	 * @return double 商品价格
	 */
	public static double calculatePrice(double goodsPrice,int userYear,int userNum,String feeFormula,double feeBasenum){
		Double price = goodsPrice * feeBasenum;
		if(feeFormula.contains("年限")) {
			price = price / 12;
		}
		String[] str = feeFormula.split("\\*");
		int userNumCount = 0, userYearCount = 0;
		for (String string : str) {
			if("用户数".equals(string.trim())) {
				userNumCount ++;
			}else if("年限".equals(string.trim())){
				userYearCount ++;
			}
		}
		
		for (int i = 0; i < userNumCount; i++) {
			price *= userNum;
		}
		
		for (int i = 0; i < userYearCount; i++) {
			price *= userYear;
		}
		return price;
	}
	
	
	public static void main(String[] args) throws ParseException {
		System.out.println(calculatePrice(100,6,3,"用户数",0.5));
	}
}
